//
//  GRNoInteractionViewController.m
//  YC_GRice
//
//  Created by LiuFeng on 2018/7/10.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRNoInteractionViewController.h"
#import <WebKit/WebKit.h>


@interface GRNoInteractionViewController () <WKNavigationDelegate>

@property (nonatomic, strong) WKWebView *webView;

@end

@implementation GRNoInteractionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.URL]]];
    
    [GRHUD showLoading:@"正在加载" atView:self.view];
}

-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
    [webView evaluateJavaScript:@"document.documentElement.style.webkitUserSelect='none';" completionHandler:nil];
    [webView evaluateJavaScript:@"document.documentElement.style.webkitTouchCallout='none';" completionHandler:nil];
    
    if (self.titleAutomation) {
        self.navigationItem.title = webView.title;
    }
    [GRHUD dismissHUD:self.view];
}


-(void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    NSURL *url = navigationAction.request.URL;
    
    if ([url.scheme isEqualToString:@"tel"]) {
        [NSObject openSystemURL:[NSString stringWithFormat:@"telprompt://%@",url.resourceSpecifier]];
    }
    
    decisionHandler(WKNavigationActionPolicyAllow);
}

-(WKWebView *)webView {
    if (!_webView) {
        _webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:[WKWebViewConfiguration new]];
        _webView.backgroundColor    = [UIColor clearColor];
        _webView.navigationDelegate = self;
        [self.view addSubview:_webView];
    }
    return _webView;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
